package com.yan.utils;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;

public class HttpClientTest {

	public static void main(String[] args) {
		//String url = "http://192.168.70.213:8080/chatServer/chat/sendPChatMessage/android/football?lang=zh&timeZone=8&message=&chatType=football&toUserId=null&sourceName=android&msgCode=1&msgId=e10ea908-dae9-4824-9ebf-5262f04d577b&thirdId=3482618&deviceId=357095063448756&userId=hhly90320&phoneNum=13570185327&userLogo=http://tp.13322.com/img/2017-06-06/9212f265-8f28-40e3-9032-a2cb412e633c.jpg&userNick=诸葛看盘";

	 	String url="http://localhost:10088/JFinal/indexJson";
		HttpClient http = new HttpClient();
		CustomGetMethod get = new CustomGetMethod(url);

		// 添加头信息告诉服务端可以对Response进行GZip压缩
		 get.setRequestHeader("Accept-Encoding", "gzip, deflate");
		try {
			int statusCode = http.executeMethod(get);
			if (statusCode != HttpStatus.SC_OK) {
				System.err.println("Method failed: " + get.getStatusLine());
			}

			// 打印解压后的返回信息
			System.out.println(get.getResponseBodyAsString());
		} catch (Exception e) {
			System.err.println("页面无法访问");
			e.printStackTrace();
		} finally {
			get.releaseConnection();
		}
	}
}
